﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Module.QuanLyDuoc
{
    public class HeThongBaoCao : DBInteractionBase
    {
        public DataTable BaoCaoTongHopPhieuNhapKho(DateTime tungay, DateTime denngay, string makho, string manhacungcap)
        {
            var dt = new DataSet();
            try
            {
                using (var dbcmd = new SqlCommand("tbDuoc_BaoCaoTongHopPhieuNhapKho", GetConnection()))
                {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.Parameters.Add(new SqlParameter("@TuNgay", tungay));
                    dbcmd.Parameters.Add(new SqlParameter("@DenNgay", denngay));
                    dbcmd.Parameters.Add(new SqlParameter("@MaKho", makho));
                    dbcmd.Parameters.Add(new SqlParameter("@MaNhaCungCap", manhacungcap));
                    var dtAdapter = new SqlDataAdapter(dbcmd);
                    dtAdapter.Fill(dt);
                    return dt.Tables[0];
                }
            }
            catch (Exception ex)
            {
                throw new Exception("tbDuoc_BaoCaoTongHopPhieuNhapKho: " + ex.Message);
            }
        }

        public DataTable BaoCaoTongHopPhieuNhapKho_ChiTiet(DateTime tungay, DateTime denngay, string makho, string manhacungcap)
        {
            var dt = new DataSet();
            try
            {
                using (var dbcmd = new SqlCommand("tbDuoc_BaoCaoTongHopPhieuNhapKho_ChiTiet", GetConnection()))
                {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.Parameters.Add(new SqlParameter("@TuNgay", tungay));
                    dbcmd.Parameters.Add(new SqlParameter("@DenNgay", denngay));
                    dbcmd.Parameters.Add(new SqlParameter("@MaKho", makho));
                    dbcmd.Parameters.Add(new SqlParameter("@MaNhaCungCap", manhacungcap));
                    var dtAdapter = new SqlDataAdapter(dbcmd);
                    dtAdapter.Fill(dt);
                    return dt.Tables[0];
                }
            }
            catch (Exception ex)
            {
                throw new Exception("tbDuoc_BaoCaoTongHopPhieuNhapKho_ChiTiet: " + ex.Message);
            }
        }
    }
}
